import 'package:aihu_getx_app/app/modules/admin_login/models/admin_login_form_model.dart';
import 'package:aihu_getx_app/app/modules/admin_login/providers/admin_login_provider.dart';
import 'package:aihu_getx_app/app/modules/commons/commons.dart';
import 'package:aihu_getx_app/app/routes/app_pages.dart';
import 'package:aihu_getx_app/utils/constants.dart';
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class AdminLoginController extends GetxController {
  final count = 0.obs;
  final _arguments = Get.arguments;
  final title = "登录".obs;
  final jump = Routes.splash.obs;
  final showPassword = false.obs;
  final usernameController = TextEditingController();
  final passwordController = TextEditingController();
  final username = "".obs;
  final password = "".obs;

  @override
  void onInit() {
    super.onInit();
  }

  @override
  void onReady() {
    LogUtil.v("Get.arguments: $_arguments");
    super.onReady();
    jump.value = _arguments?[Constants.jumpArgument] ??
        Commons.getCurrentClientConfig().indexPage;
  }

  @override
  void onClose() {
    super.onClose();
  }

  void increment() => count.value++;

  void login(AdminLoginFormModel form) async {
    AdminLoginProvider.login(form).then(
      (res) => {
        Get.offAllNamed(jump.value),
      },
      onError: (err) {
        LogUtil.e(err);
      },
    );
  }
}
